<?php
declare (strict_types = 1);

namespace app\controller\admin;

use app\model\Log;
use think\response\Json;

class AdminLog extends AdminBase
{

	protected $middleware = [
        'app\middleware\AdminLogin',
		'app\middleware\AdminAuth'
	];

	private string $menuName = '系统日志';

    /**
     * 显示资源列表
     * @throws
     * @return Json
     */
    public function index():Json
    {
        $limit = input('pageSize/d',10);
        //分页配置
        $pageConfig = ['list_rows'=>$limit,'var_page'=>'pageNum'];

        //搜索字段配置
        $search = [
            [
                'label'=>'管理用户',
                'prop'=> 'admin',
                'field' => 'admin',//查询字段
                'placeholder'=> '请输入用户昵称',
                'required'=> false,
                'expression'=> 'like',//查询表达式：like,not like,in,not in,between,not between,null,not null,time,>,<,>=,<=,=,<>(!=),find(FIND_IN_SET)
                'type'=> 'input',//类型：input,select,date,datetime,year,month,week,datetimerange,daterange
                'typeof' => 's',//强制转换类型：d整数，a数组，s字符串，b布尔类型，f浮点数
            ],
            [
                'label'=>'接口名称',
                'prop'=> 'action_',
                'field' => 'action',//查询字段
                'placeholder'=> '请输入接口名称',
                'required'=> false,
                'expression'=> 'like',//查询表达式：like,not like,in,not in,between,not between,null,not null,time,>,<,>=,<=,=,<>(!=),find(FIND_IN_SET)
                'type'=> 'input',//类型：input,select,date,datetime,year,month,week,datetimerange,daterange
                'typeof' => 's',//强制转换类型：d整数，a数组，s字符串，b布尔类型，f浮点数
            ],
            [
                'label'=>'说明',
                'prop'=> 'msg',
                'field' => 'msg',//查询字段
                'placeholder'=> '请输入说明',
                'required'=> false,
                'expression'=> 'like',//查询表达式：like,not like,in,not in,between,not between,null,not null,time,>,<,>=,<=,=,<>(!=),find(FIND_IN_SET)
                'type'=> 'input',//类型：input,select,date,datetime,year,month,week,datetimerange,daterange
                'typeof' => 's',//强制转换类型：d整数，a数组，s字符串，b布尔类型，f浮点数
            ],
            [
                'label'=>'IP',
                'prop'=> 'ip',
                'field' => 'ip',//查询字段
                'placeholder'=> '请输入ip',
                'required'=> false,
                'expression'=> 'like',//查询表达式：like,not like,in,not in,between,not between,null,not null,time,>,<,>=,<=,=,<>(!=),find(FIND_IN_SET)
                'type'=> 'input',//类型：input,select,date,datetime,year,month,week,datetimerange,daterange
                'typeof' => 's',//强制转换类型：d整数，a数组，s字符串，b布尔类型，f浮点数
            ],
        ];

        $map = [];
        $this->setMap($search,$map);

		$data = Log::where($map)
            ->order('create_time','desc')
			->paginate($pageConfig);

		$this->result['data'] = [
            'total' => $data->total(),
            'data' => $data->items(),
            'search' => $search
        ];
		return jJson($this->result);
    }

    /**
     * 删除指定资源
     * @throws
     * @return Json
     */
    public function delete():Json
    {

        $id = (string) input('id','');
        $ids = explode(',',$id);

        Log::destroy($ids);

        $this->result['msg'] = '删除ID：'.$id;

        return returnAdmin($this->request,$this->result,$this->menuName.'-删除',$this->adminInfo);
    }

}
